package com.foo.ui_demo_layout3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnSubmit = findViewById(R.id.btn_submit);
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StringBuilder sb = new StringBuilder();
                EditText etName = findViewById(R.id.et_name);
                sb.append("姓名:" + etName.getText().toString());
                sb.append(",");
                Spinner ddClass = findViewById(R.id.dd_class);
                sb.append("班级:" + ddClass.getSelectedItem().toString());
                sb.append(",");
                CheckBox cbBasketball = findViewById(R.id.cb_basketball);
                CheckBox cbMusic = findViewById(R.id.cb_music);
                CheckBox cbTravel = findViewById(R.id.cb_travel);
                CheckBox cbGame = findViewById(R.id.cb_game);
                sb.append("爱好:");
                if (cbBasketball.isChecked()){
                    sb.append(cbBasketball.getText().toString()+" ");
                }
                if (cbMusic.isChecked()){
                    sb.append(cbMusic.getText().toString()+" ");
                }
                if (cbTravel.isChecked()){
                    sb.append(cbTravel.getText().toString()+" ");
                }
                if (cbGame.isChecked()){
                    sb.append(cbGame.getText().toString()+" ");
                }
                sb.append(",");
                sb.append("成绩:");
                RadioGroup rgGrade = findViewById(R.id.rg_grade);
                RadioButton rbChecked = findViewById(rgGrade.getCheckedRadioButtonId());
                sb.append(rbChecked.getText().toString());
                Toast.makeText(MainActivity.this,sb.toString(),Toast.LENGTH_LONG).show();
            }
        });
    }
}